package com.fan.txl.mock.api.service.mock;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.fan.txl.mock.api.annotation.MockRspData;
import com.fan.txl.mock.api.annotation.MockRspParse;
import retrofit2.mock.BehaviorDelegate;

/**
 * Created by jiajiabao on 17-1-16.
 */

public class MockService<V> extends Service{


    public final BehaviorDelegate<V> delegate;

    public MockService(BehaviorDelegate<V> delegate) {
        this.delegate = delegate;
    }

    @Deprecated
    public <T>T mock(TypeReference<T> type,Class<? extends MockService> child,String methodName){
        MockRspData mockRspData= MockRspParse.parseAnnotation(child,methodName);
        //读取数据
        String body=readMockRsp(mockRspData);
        //转换数据
        T rsp= JSON.parseObject(body,type);
        return rsp;
    }


    public String mock(String service,String method){
        String body=readMockRsp(service,method);
        return body;
    }
}
